package studentinformationmanagementsystem.dao.impl;

import studentinformationmanagementsystem.dao.BaseDao;
import studentinformationmanagementsystem.dao.TeachersSchedulesDao;
import studentinformationmanagementsystem.entity.TakeACourse;
import studentinformationmanagementsystem.entity.TeachersSchedules;

import java.util.List;

/**
 * @author 苗庆
 * @version 1.0
 * 教师任课表dao层
 */
public class TeachersSchedulesDaolmpl extends BaseDao implements TeachersSchedulesDao {


    /**
     * 对教师任课信息进行添加
     * @param teachersSchedules  教师任课对象
     * @return  受影响的记录行数
     */
    @Override
    public int insert(TeachersSchedules teachersSchedules) {

        String sql = "INSERT INTO `t_teachersschedules` (`courseid`, `teacherid`) VALUES (?, ?)";
        return super.update(sql,teachersSchedules.getCourseid(),teachersSchedules.getTeacherid());

    }


    /**
     *  根据ID更新教师任课信息
     * @param teachersSchedules  教师任课对象
     * @return 受影响的记录行数
     */
    @Override
    public int update(TeachersSchedules teachersSchedules) {
        String sql = "UPDATE `t_teachersschedules` SET `courseid` = ? , `teacherid` = ? WHERE `teachersschedulesid` = ? ";
        return super.update(sql,teachersSchedules.getCourseid(),teachersSchedules.getTeacherid(),teachersSchedules.getTeachersschedulesid());
    }


    /**
     *  根据ID删除教师任课
     * @param teachersSchedules 教师任课ID
     * @return 受影响的记录行数
     */
    @Override
    public int delete(TeachersSchedules teachersSchedules) {
        String sql = "DELETE FROM `t_teachersschedules` WHERE `teachersschedulesid` = ?";
        return super.update(sql, teachersSchedules.getTeachersschedulesid());
    }



    /**
     * 查询所有教师任课信息
     * @return 所有教师任课信息
     */
    @Override
    public List<TeachersSchedules> queryAll() {
        String sql = "SELECT * FROM `t_teachersschedules`";
        return super.queryForList(TeachersSchedules.class, sql);
    }


    /**
     * 根据教师任课ID查询教师任课信息
     * @param teachersSchedules 教师任课ID
     * @return 教师任课信息
     */
    @Override
    public TeachersSchedules queryById(TeachersSchedules teachersSchedules) {
        String sql = "SELECT * FROM `t_teachersschedules` WHERE `teachersschedulesid` = ?";
        return super.queryForOne(TeachersSchedules.class, sql, teachersSchedules.getTeachersschedulesid());
    }

    /**
     * 根据课程表id查询教师任课信息
     * @param teachersSchedules 课程表id
     * @return 教师任课信息
     */
    @Override
    public TeachersSchedules queryBycourseid(TeachersSchedules teachersSchedules) {
        String sql = "SELECT * FROM `t_teachersschedules` WHERE `courseid` = ?";
        return super.queryForOne(TeachersSchedules.class, sql, teachersSchedules.getCourseid());
    }


    /**
     * 根据教师表id查询教师任课信息
     * @param teachersSchedules 教师表表id
     * @return 教师任课信息
     */
    @Override
    public TeachersSchedules queryByteacherid(TeachersSchedules teachersSchedules) {
        String sql = "SELECT * FROM `t_teachersschedules` WHERE `teacherid` = ?";
        return super.queryForOne(TeachersSchedules.class, sql, teachersSchedules.getTeacherid());
    }
}
